﻿using System;

namespace WpfClient.FunctionFileParsing
{
    public class IndifferentStateHandler : FunctionFileParsingStateHandlerBase
    {
        private const string ClassDefinitionString = "public class";
        private const string FunctionNameInitializationString = "string FunctionName = \"";

        public IndifferentStateHandler(FunctionFileParserContext context)
            : base(context)
        {
        }

        protected override FunctionFileParsingState Handle(char symbol)
        {
            string buffer = this.ParserContext.Buffer.ToString();

            if (buffer.EndsWith(FunctionNameInitializationString))
            {
                return FunctionFileParsingState.FunctionName;
            }

            if (!this.ParserContext.HasReachedClassDefinition && buffer.EndsWith(ClassDefinitionString))
            {
                this.ParserContext.Result.ClassStartIndex = buffer.Substring(0, buffer.Length - ClassDefinitionString.Length).Length;
                this.ParserContext.HasReachedClassDefinition = true;
            }

            return FunctionFileParsingState.Indifferent;
        }
    }
}
